<?php


namespace app\logic\model;


use think\Model;

class MintTransferLogModel extends Model
{
    protected $name='mint_transfer_log';
    function getTypeAttr($val){
        $arr=array(
            'msg'=>'未知',
            'val'=>$val
        );
        if($val==1){
            $arr['msg']='购买';
        }elseif ($val==2){
            $arr['msg']='赠送';
        }elseif ($val==3){
            $arr['msg']='后台赠送';
        }
        return $arr;
    }
    function getList($param,$field,$limit){
        $list=$this->alias('mtl')
            ->leftJoin('user from','from.id=mtl.transfer_from_user_id')
            ->leftJoin('user to','to.id=mtl.transfer_to_user_id')
            ->leftJoin('opus_number on','on.id=mtl.transfer_opus_number_id')
            ->leftJoin('opus o','o.id=mtl.opus_id')
            ->where(function($q) use ($param){
                if(check_request($param,'from_user')){
                    $q->whereLike('from.nickname|form.true_name|form.mobile',"%{$param['form_user']}%");
                }
                if(check_request($param,'to_user')){
                    $q->whereLike('to.nickname|to.true_name|to.mobile',"%{$param['to_user']}%");
                }
                if(check_request($param,'opus_number')){
                    $q->whereLike('on.number',"%{$param['opus_number']}%");
                }
                if(check_request($param,'opus_title')){
                    $q->whereLike('o.title',"%{$param['opus_title']}%");
                }
            })->order('id desc')->field($field)->paginate($limit);
        if(!$list->isEmpty()){
            return $list->toArray();
        }
        return $list;
    }
}